#!/bin/bash

#clean the data file
echo \#start >figure10_true.dat
echo \#start >figure10_false.dat

#run the simulation 10 times
simulation_red_true()
{ # $1 is the first parameter of simulation()
n1=$1

for simulation_i in  1 2 3 4 5 6 7 8 9 10; do
	ns red-true.tcl $n1 $simulation_i 
done
}

simulation_red_false()
{ # $1 is the first parameter of simulation()
n1=$1

for simulation_i in  1 2 3 4 5 6 7 8 9 10; do
	ns red-false.tcl $n1 $simulation_i
done
}

#run the simulation with differen buffer size
#for buffersize_i in 3 5 7 9 11 13 15 20 25 30 40 50; do
for ((buffersize_i=1; buffersize_i<=50; buffersize_i=buffersize_i+1)) do
	simulation_red_true $buffersize_i >temp_data
	cat temp_data | awk 'BEGIN{delay=0; throughput=0} {if ($2=="delay"){delay=delay+$5}; 
 			if ($2=="throughput"){throughput=throughput+$5}} 
			END{print 100*(delay/10)/0.017, (throughput/10)/45.0}' >> figure10_true.dat
done

#for buffersize_i in 3 5 7 9 11 13 15 20 25 30 40 50; do
for ((buffersize_i=1; buffersize_i<=50; buffersize_i=buffersize_i+1)) do
	simulation_red_false $buffersize_i >temp_data
	cat temp_data | awk 'BEGIN{delay=0; throughput=0} {if ($2=="delay"){delay=delay+$5}; 
 			if ($2=="throughput"){throughput=throughput+$5}} 
			END{print 100*(delay/10)/0.017, (throughput/10)/45.0}' >> figure10_false.dat
done

#plot the graph
gnuplot figure10.plt
